home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 28
/
Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso
/
Aminet
/
game
/
board
/
Crafty-15.19.lha
/
crafty-15.19
/
src
/
movgen.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-09-13
|
53KB
|
1,292 lines
#include <stdio.h>
#include <stdlib.h>
#include "chess.h"
#include "data.h"
/* modified 03/11/97 */
/*
********************************************************************************
* *
* GenerateCaptures() is used to generate capture and pawn promotion moves *
* from the current position. *
* *
* the destination square set is the set of squares occupied by opponent *
* pieces, plus the set of squares on the 8th rank that pawns can advance to *
* and promote. *
* *
********************************************************************************
*/
int* GenerateCaptures(TREE *tree, int ply, int wtm, int *move)
{
register BITBOARD target, piecebd, moves;
register BITBOARD promotions, pcapturesl, pcapturesr;
register int from, to, temp;
if (wtm) {
/*
----------------------------------------------------------
| |
| now, produce knight moves by cycling through the |
| *_knight board to locate a [from] square and then |
| cycling through knight_attacks[] to locate to squares |
| that a knight on [from] attacks. |
| |
----------------------------------------------------------
*/
piecebd=WhiteKnights;
while (piecebd) {
from=LastOne(piecebd);
moves=And(knight_attacks[from],BlackPieces);
temp=from+(knight<<12);
while (moves) {
to=LastOne(moves);
*move++=temp|(to<<6)|((-PieceOnSquare(to))<<15);
Clear(to,moves);
}
Clear(from,piecebd);
}
/*
----------------------------------------------------------
| |
| now, produce bishop moves by cycling through the |
| *_bishop board to locate a [from] square and then |
| generate the AttacksFrom() bitmap which supplies the |
| list of valid <to> squares. |
| |
----------------------------------------------------------
*/
piecebd=WhiteBishops;
while (piecebd) {
from=LastOne(piecebd);
moves=And(AttacksBishop(from),BlackPieces);
temp=from+(bishop<<12);
while (moves) {
to=LastOne(moves);
*move++=temp|(to<<6)|((-PieceOnSquare(to))<<15);
Clear(to,moves);
}
Clear(from,piecebd);
}
/*
----------------------------------------------------------
| |
| now, produce rook moves by cycling through the |
| *_rook board to locate a [from] square and then |
| generate the AttacksFrom() bitmap which supplies the |
| list of valid <to> squares. |
| |
----------------------------------------------------------
*/
piecebd=WhiteRooks;
while (piecebd) {
from=LastOne(piecebd);
moves=And(AttacksRook(from),BlackPieces);
temp=from+(rook<<12);
while (moves) {
to=LastOne(moves);
*move++=temp|(to<<6)|((-PieceOnSquare(to))<<15);
Clear(to,moves);
}
Clear(from,piecebd);
}
/*
----------------------------------------------------------
| |
| now, produce queen moves by cycling through the |
| *_queen board to locate a [from] square and then |
| generate the AttacksFrom() bitmap which supplies the |
| list of valid <to> squares. |
| |
----------------------------------------------------------
*/
piecebd=WhiteQueens;
while (piecebd) {
from=LastOne(piecebd);
moves=And(AttacksQueen(from),BlackPieces);
temp=from+(queen<<12);
while (moves) {
to=LastOne(moves);
*move++=temp|(to<<6)|((-PieceOnSquare(to))<<15);
Clear(to,moves);
}
Clear(from,piecebd);
}
/*
----------------------------------------------------------
| |
| now, produce king moves by cycling through the |
| *_king board to locate a [from] square and then |
| cycling through king_attacks[] to locate to squares |
| that a king on [from] attacks. |
| |
----------------------------------------------------------
*/
from=WhiteKingSQ;
moves=And(king_attacks[from],BlackPieces);
temp=from+(king<<12);
while (moves) {
to=LastOne(moves);
*move++=temp|(to<<6)|((-PieceOnSquare(to))<<15);
Clear(to,moves);
}
/*
----------------------------------------------------------
| |
| now, produce pawn moves. this is done differently due |
| to inconsistencies in the way a pawn moves when it |
| captures as opposed to normal non-capturing moves. |
| another exception is capturing enpassant. the first |
| step is to generate all possible pawn promotions. we |
| do this by masking all pawns but those on the 7th |
| rank and then advancing them ahead if the square in |
| front is empty. |
| |
----------------------------------------------------------
*/
promotions=And(Shiftr(And(WhitePawns,rank_mask[RANK7]),8),Compl(Occupied));
while (promotions) {
to=LastOne(promotions);
*move++=(to-8)|(to<<6)|(pawn<<12)|(queen<<18);
Clear(to,promotions);
}
target=Or(BlackPieces,EnPassantTarget(ply));
pcapturesl=And(Shiftr(And(WhitePawns,mask_left_edge),7),target);
while (pcapturesl) {
to=LastOne(pcapturesl);
if (to < 56) {
if(PieceOnSquare(to))
*move++=(to-7)|(to<<6)|(pawn<<12)|((-PieceOnSquare(to))<<15);
else
*move++=(to-7)|(to<<6)|(pawn<<12)|(pawn<<15);
}
else
*move++=(to-7)|(to<<6)|(pawn<<12)|((-PieceOnSquare(to))<<15)|(queen<<18);
Clear(to,pcapturesl);
}
pcapturesr=And(Shiftr(And(WhitePawns,mask_right_edge),9),target);
while (pcapturesr) {
to=LastOne(pcapturesr);
if (to < 56) {
if(PieceOnSquare(to))
*move++=(to-9)|(to<<6)|(pawn<<12)|(-PieceOnSquare(to)<<15);
else
*move++=(to-9)|(to<<6)|(pawn<<12)|(pawn<<15);
}
else
*move++=(to-9)|(to<<6)|(pawn<<12)|((-PieceOnSquare(to))<<15)|(queen<<18);
Clear(to,pcapturesr);
}
}
/*
----------------------------------------------------------
| |
| now, produce knight moves by cycling through the |
| *_knight board to locate a [from] square and then |
| cycling through knight_attacks[] to locate to squares |
| that a knight on [from] attacks. |
| |
----------------------------------------------------------
*/
else {
piecebd=BlackKnights;
while (piecebd) {
from=FirstOne(piecebd);
moves=And(knight_attacks[from],WhitePieces);
temp=from+(knight<<12);
while (moves) {
to=FirstOne(moves);
*move++=temp|(to<<6)|(PieceOnSquare(to)<<15);
Clear(to,moves);
}
Clear(from,piecebd);
}
/*
----------------------------------------------------------
| |
| now, produce bishop moves by cycling through the |
| *_bishop board to locate a [from] square and then |
| generate the AttacksFrom() bitmap which supplies the |
| list of valid